//
//  FilmViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/3/24.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "FilmViewController.h"
#import "FilmTimeTableViewCell.h"
#import "PageScroView.h"
#import "ZXMovieBrowser.h"
static NSString * cellIndentfier = @"FilmTimeTableViewCell";
@interface FilmViewController ()<UITableViewDelegate,UITableViewDataSource,ZXMovieBrowserDelegate>
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroView;
@property (strong, nonatomic) IBOutlet UIView *noticeView;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) IBOutlet UILabel *movieName;
@property (strong, nonatomic) IBOutlet UILabel *movieTime;
@property (nonatomic,strong) ZXMovieBrowser *movieBrowser;
@property (nonatomic, strong, readwrite) NSMutableArray *movies;

@end

@implementation FilmViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _movies = [NSMutableArray array];
    self.rightSwipeGesture.enabled = NO;
    [self initViewLayout];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    [self adaptiveViewLayout:self.noticeView];
    
    [self setupCardView];
    
    [self.tableView registerNib:[UINib nibWithNibName:cellIndentfier bundle:nil] forCellReuseIdentifier:cellIndentfier];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    PageScroView * pageView = [[PageScroView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 225, 320, 35), YES) Titles:@[@"今天2月21日",@"今天2月21日",@"今天2月21日",@"今天2月21日",@"今天2月21日",@"今天2月21日",@"今天2月21日"] complect:^(NSInteger index) {
        
    }];
    [_scroView addSubview:pageView];
    
}

- (void)setupCardView{
    NSArray * names = @[@"海底总动员2",@"愤怒的小鸟",@"魔兽",@"爱丽丝梦游仙境2"];
    NSArray * urls = @[@"https://img3.doubanio.com/view/movie_poster_cover/spst/public/p2356015154.jpg",@"https://img3.doubanio.com/view/movie_poster_cover/spst/public/p2352310242.jpg",@"https://img1.doubanio.com/view/movie_poster_cover/spst/public/p2345947329.jpg",@"https://img3.doubanio.com/view/movie_poster_cover/spst/public/p2349374680.jpg"];
    for (int i = 0;i<4 ;i++) {
        ZXMovie *movie = [[ZXMovie alloc] init];
        movie.name = names[i];
        movie.coverUrl = urls[i];
        [self.movies addObject:movie];
    }
    
    ZXMovieBrowser *movieBrowser = [[ZXMovieBrowser alloc] initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 137), NO) movies:self.movies currentIndex:1];
    movieBrowser.delegate = self;
    [self.scroView addSubview:movieBrowser];
    self.movieBrowser = movieBrowser;
}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}
#pragma mark == 影院详情
- (IBAction)filmDetail:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"FilmDetail"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark == 电影详情
- (IBAction)movieDetail:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"MovieDetail"];
    [self.navigationController   pushViewController:page animated:YES];
    
}


#pragma mark ZXMovieBrowserDelegate

- (void)movieBrowser:(ZXMovieBrowser *)movieBrowser didSelectItemAtIndex:(NSInteger)index
{
}

- (void)movieBrowser:(ZXMovieBrowser *)movieBrowser didChangeItemAtIndex:(NSInteger)index
{
    NSMutableAttributedString * str = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@",((ZXMovie *)self.movies[index]).name,@"9.0分"]];
    [str addAttribute:NSForegroundColorAttributeName value:kGetColor(250, 159, 0) range:NSMakeRange(str.length-4, 4)];
    self.movieName.attributedText = str;
}
static NSInteger _lastIndex = -1;
- (void)movieBrowser:(ZXMovieBrowser *)movieBrowser didEndScrollingAtIndex:(NSInteger)index
{
}

#pragma mark -- UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

        return 58*VerticalRatio();
        

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 
        return 4;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FilmTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfier];
    if (cell == nil) {
        cell= [[FilmTimeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfier];
        
    }
    
    for (UIView *view in cell.subviews) {
        if ([view isKindOfClass:[UILabel class]] ||[view isKindOfClass:[UIImageView class]]||[view isKindOfClass:[UIScrollView class]]||[view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    cell.choseBlock = ^(NSString * str){
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ChoseSeat"];
        [self.navigationController   pushViewController:page animated:YES];
    };
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
